package com.cd.university.config.security.validate;

import lombok.Data;

import java.time.LocalDateTime;

/**
 * 验证码的通用实体类
 * 后面具体的验证码实体只需要继承这个类即可
 * @author 陈栋
 * @create 2021/9/4 10:57
 */
@Data
public class ValidateCode {

    private String code;

    private LocalDateTime expireTime;

    /**
     * 初始化参数
     * @param code 验证码
     * @param expireIn 过期时间
     */
    public ValidateCode(String code, int expireIn) {
        this.code = code;
        // 当前存入的code时间是向后推expireIn秒
        this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
    }

    public ValidateCode(String code, LocalDateTime expireTime) {
        this.code = code;
        this.expireTime = expireTime;
    }

    /**
     * 判断当前是否过期
     * @return 如果过期返回false
     */
    public boolean isExpried() {
        return LocalDateTime.now().isAfter(expireTime);
    }
}
